﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Inherits="Pages_Operators_ServiceList" Codebehind="ServiceList.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="using" runat="Server">

    <script type="text/javascript" src="/Pages/Operators/Js/service.js"></script>

    <script type="text/javascript" src="/js/smartpaginator.js"></script>

    <link href="/css/smartpaginator.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="header" runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="content" runat="Server">
    <div style="margin: 5px">
        <table id="condition">
            <tr>
                <td>
                    <!-- Title -->
                    <h1>
                        Search Services</h1>
                </td>
            </tr>
            <tr>
                <%-- Service Code, Name, Find and Excel --%>
                <td>
                    <div class="label">
                        Service#:</div>
                    <div class="field">
                        <asp:TextBox ID="txtServiceCode" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <div class="label">
                        Service Name:</div>
                    <div class="field">
                        <asp:TextBox ID="txtServiceName" runat="server"></asp:TextBox>
                    </div>
                </td>
                <td>
                    <a id="btnFind" runat="server" title="Search button" class="button" href="javascript:void(0)">
                        <span>Search</span></a> <a id="btnExcel" runat="server" title="Excel button" class="button"
                            href="javascript:void(0)"><span>Excel</span></a>
                </td>
            </tr>
        </table>
        <div id="service">
        </div>
        <div id="red" style="margin: auto;">
        </div>
    </div>

    <script type="text/javascript">
        var pageSize = 20;

        $(document).ready(function () {

            // Get Data
            function getData(pageNumber, pagelink) {
                var serviceCode = $("#<%=txtServiceCode.ClientID %>").val();
                var serviceName = $("#<%=txtServiceName.ClientID %>").val();

                defaultParameters = "{serviceCode:'" + serviceCode + "', serviceName: '" + serviceName + "', pageSize:" + pageSize + ", pageNumber:" + pageNumber + "}";
                //    Loader(true);
                loading($('#service'));
                $.ajax({
                    type: "POST",
                    url: "/Get.asmx/GetServiceList",
                    data: defaultParameters,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: (function Success(data, status) {
                        var list = data.d;
                        $('#service').setTemplateURL("/Pages/Operators/template/serviceListTemplate.htm");
                        $('#service').processTemplate(list);

                        //                        setPageNumber(pageSize);
                        if (pagelink != null) {
                            $('#red').smartpaginator({
                                totalrecords: list.TotalRecords,
                                recordsperpage: list.PageSize,
                                length: 8,
                                next: 'Next',
                                prev: 'Prev',
                                first: 'First',
                                last: 'Last',
                                theme: 'red',
                                controlsalways: true,
                                onchange: function (newPage) {
                                    getData(newPage);
                                    $('#r').html('Page # ' + newPage);
                                }
                            });
                        }

                        defineButtons();

                    }),
                    error: (function Error(request, status, error) {
                        $("#service").html(request.statusText).fadeIn(1000);
                    })
                });
            }

            // Set Page Number
            //            function setPageNumber() {
            //                $(".pagenumber").click(function() {
            //                    $(".pagenumber").removeClass("actived");
            //                    $(this).addClass("actived");

            //                    var pageIndex = $(this).val();
            //                    if (pageIndex != -1)
            //                        getData(pageIndex);
            //                });
            //            }

            // Define Buttons
            function defineButtons() {
                $("#gridService a.btnNew").button();

                $("#gridService a.btnDelete").click(function () {
                    var result = confirm("Are you sure you want to delete this record?");
                    if (result) {
                        var aTag = $(this);

                        // load provider
                        $.ajax({
                            type: "POST",
                            url: "/Update.asmx/DeleteService",
                            data: "{ serviceID:'" + aTag.attr("serviceid") + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            async: false,
                            success: (function Success(data, status) {
                                if (data.d) {
                                    // Select provider
                                    $('#gridService > tbody > tr').removeClass('selected');
                                    aTag.parents("tr:first").remove();
                                    return false;
                                }
                            }),
                            error: (function Error(request, status, error) {
                                $("#service").html(request.statusText).fadeIn(1000);
                            })
                        });
                    }
                });
            }

            $("#<%=btnFind.ClientID %>").click(function () {
                getData(1, true);
            });

            $("#<%=btnExcel.ClientID %>").click(function () {
                getData(1, true);
            });

            $(".field").keydown(function (event) {
                if (event.keyCode == '13') {
                    getData(1, true);
                    return false;
                }
            });

            getData(1, true);
        });
        
    </script>

</asp:Content>
